package com.limeng.datastruts;

import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

public class ShowNodeList {

    private Node head = new Node(0,"");
    static long lastMilliseconds ;
    private static Properties properties = new Properties();

    public static void main(String[] args) {
        long key = SnowflakeKeyGenerator.getNextKey();
        System.out.println(key+":"+String.valueOf(key).length());
        ShowNodeList func = new ShowNodeList();
        func.addNodeOrderById(new Node(4,"马超"));
        func.addNodeOrderById(new Node(5,"黄忠"));
        func.addNodeOrderById(new Node(3,"赵云"));
        func.addNodeOrderById(new Node(1,"关羽"));
        func.addNodeOrderById(new Node(2,"张飞"));
        func.print();
    }

    private void addNode(Node node){
        Node tmp = head;
        while(true){
            if(tmp.next==null){
                break;
            }
            tmp = tmp.next;
        }
        tmp.next = node;
    }

    private void addNodeOrderById(Node node){
        Node tmp = head;
        while(true){
            if(tmp.next==null){
                break;
            }
            if(tmp.next.id>node.id){
                break;
            }
            tmp = tmp.next;
        }
        node.next = tmp.next;
        tmp.next = node;
    }


    private void print(){
        if(head.next==null){
            System.out.println("empty node");
            return;
        }
        Node tmp = head.next;
        while(true){
            System.out.println(tmp);
            if(tmp.next==null){
                break;
            }
            tmp = tmp.next;
        }
    }


    static class Node{
        int id;
        String name;
        Node next;
        public Node() {
        }

        public Node(int id,String name) {
            this.id = id;
            this.name = name;
        }

        @Override
        public String toString() {
            return "Node{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    '}';
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Node getNext() {
            return next;
        }

        public void setNext(Node next) {
            this.next = next;
        }
    }
}
